package com.xbstar.tools;

import org.json.JSONException;
import org.json.JSONObject;

public class HttpPackageBuilder{
	
	private JSONObject httpPkgInfo;//全部包信息
	
	public JSONObject getOperationData(){
		JSONObject od = new JSONObject();
		try {
			if(this.httpPkgInfo.has("OperationData")){
				od =  (JSONObject) this.httpPkgInfo.get("OperationData");
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return od;
	}
	
	
	public JSONObject getHttpPackageBuilder()
	{
		return this.httpPkgInfo;
	}
	
	public HttpPackageBuilder()
	{
		this.httpPkgInfo = new JSONObject();
	}
	
	//构造函数1 传入参数 jsonobject
	public HttpPackageBuilder(JSONObject obj)
	{
		this.httpPkgInfo = obj;
	}
	
	//构造函数1 传入参数 字符串
	public HttpPackageBuilder(String obj)
	{
		try {
			this.httpPkgInfo = new JSONObject(obj);
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
	
	public void setHttpPackageBuilder(String obj){
		try {
			this.httpPkgInfo = new JSONObject(obj);
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
	
	public void setHttpPackageBuilder(JSONObject obj){
		this.httpPkgInfo = obj;
	}
	
	public int getOperationCode(){
		int code = -1;
		try {
			code =  (Integer) this.httpPkgInfo.get("OperationCode");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return code;
	}
	
	public void setOperationCode(int code){
		try {
			 this.httpPkgInfo.put("OperationCode",code);
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
	
	public String getUserLoginId(){
		String userLoginId = "";
		try {
			JSONObject operationData  =  (JSONObject) this.httpPkgInfo.get("OperationData");
			if(operationData.has("userLoginId")){
				userLoginId = (String) operationData.get("userLoginId");
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return userLoginId;
	}
	
	public String getRegisterId(){
		String registerId = "";
		try {
			JSONObject operationData  =  (JSONObject) this.httpPkgInfo.get("OperationData");
			if(operationData.has("registerId")){
				registerId = (String) operationData.get("registerId");
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return registerId;
	}
	
	public String getPkgName(){
		String pkgName = "";
		try {
			JSONObject operationData  =  (JSONObject) this.httpPkgInfo.get("OperationData");
			if(operationData.has("Pacakge")){
				pkgName = (String) operationData.get("Pacakge");
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return pkgName;
	}
	
}